package com.elite;

import java.io.FileInputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.com.elite.util;

public class FtpServlet extends HttpServlet{
	private static final Log log=LogFactory.getLog(FtpServlet.class);
	private DBSMS fileftp;
	private Thread t; 
	private Thread t1;
	public void destroy() {
		log.info("服务器关闭!");
	}
	
	public void init(){
		log.info("-------------Servlet Start----------------");
		try{
			fileftp = new DBSMS();
			fileftp.setTimes(this.getInitParameter("DOTIME"));
			fileftp.setUsername(this.getInitParameter("username"));
			fileftp.setPassword(this.getInitParameter("password"));
			fileftp.setIP(this.getInitParameter("IP")); 
		}catch(Exception e){
			log.info("获取XML参数出错:"+e);
		}
		
		try{
	        ServletContext application;   
	        WebApplicationContext wac;   
	        application = getServletContext();   
	        wac = WebApplicationContextUtils.getWebApplicationContext(application);//获取spring的context  
	        com.elite.FtpBean ftpbean = (com.elite.FtpBean) wac.getBean("ftpbean");  
	        fileftp.setFtpbean(ftpbean);
	    	t = new Thread(fileftp); 
	        t.start(); //   启动定时短信任务
		}catch(Exception e){
			log.info(util.getERRO(e));
		}
        log.info("启动定时短信任务 ");

	}

}
